package sz.szsmk.citizencard.retrofitrxjava.newversion.interceptor

import android.os.Build
import okhttp3.Interceptor
import okhttp3.Response
import sz.szsmk.citizencard.BuildConfig
import sz.szsmk.citizencard.DaggerApplication
import sz.szsmk.citizencard.util.ACache
import java.util.*

/**
 *  author : hyt
 *  date : 2020/11/26
 *  description : 头部拦截器 http 头 增加附带参数
 */
class HeadParamInterceptor:Interceptor {
    override fun intercept(chain: Interceptor.Chain): Response {
        val request = chain.request()

        var newRequest = request.newBuilder()
                //平台
                .addHeader("Platform", "android")
                //版本号
                .addHeader("Version", BuildConfig.VERSION_NAME)
                 //时区   值:Asia/Shanghai
                .addHeader("TimeZone", TimeZone.getDefault().id)
                //语言
                .addHeader("Language",  DaggerApplication.getIns().resources.configuration.locale.language)
                //型号
                .addHeader("Model",  Build.MODEL)
                //SDK版本
                .addHeader("SDKVersion", Build.VERSION.RELEASE)

        if(ACache.get(DaggerApplication.getIns()).getAsString("Access_token")!=null){
            //token
            newRequest.addHeader("accessToken", ACache.get(DaggerApplication.getIns()).getAsString("Access_token"))
        }

        return chain.proceed(newRequest.build())
    }
}